package com.qingcheng.controller.goods;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.goods.Album;
import com.qingcheng.service.goods.AlbumService;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/album")
public class AlbumController {

    @Reference
    private AlbumService albumService;

    @GetMapping("/findAll")
    public List<Album> findAll(){
        return albumService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Album> findPage(int page, int size){
        return albumService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Album> findList(@RequestBody Map<String,Object> searchMap){
        return albumService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Album> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  albumService.findPage(searchMap,page,size);
    }
    //{{},{}}
    @GetMapping("/findById")
    public Album findById(Long id){
        Album albumServiceById = albumService.findById(id);
        return albumServiceById;
    }


    @PostMapping("/add")
    public Result add(@RequestBody Album album){
        albumService.add(album);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Album album){
        albumService.update(album);
        return new Result();
    }

    /**
     * url  /album/delete.do
     * 批量删除图片
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody ArrayList<String> imageList,Long id){
        albumService.delete(imageList,id);
        return new Result();
    }

    /**
     * url: /album/addMany
     * 添加相册集合
     * @param imageUrls
     * @param id
     * @return
     */
    @PostMapping("/addMany")

    public Result addManyById(@RequestBody ArrayList<Object> imageUrls,int id){
        //调用service方法,,根据相册id 添加相册列表
        albumService.addMany(imageUrls, id);
        return new Result();
    }

}
